<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.easidea.tim.service.saleorder.SaleOrderService"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.easidea.tim.entity.saleorder.SaleOrder"%>
<%@page import="com.easidea.tim.entity.saleorder.SaleOrderItem"%>
<%@page import="com.easidea.tim.dao.saleorder.SaleOrderItemDao"%>
<%@page import="com.easidea.tim.service.inventory.StorageService"%>
<%@page import="org.hibernate.Session"%>
<%@page import="com.easidea.tim.service.saleorder.SaleOrderItemService"%>
<%
	String orderid = request.getParameter("orderid").toString();
	String meterstring = request.getParameter("meterstring").toString();
	String itemid = request.getParameter("itemid").toString();

	
	SaleOrderService saleOrderService = new SaleOrderService();
	StorageService storageService = new StorageService();
	SaleOrderItemService saleOrderItemService = new SaleOrderItemService();

	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
	List list = ((SaleOrderItemService)wac.getBean("saleOrderItemService")).getItemsById(Long.parseLong(itemid));
	List itemList = ((SaleOrderItemService)wac.getBean("saleOrderItemService")).getItemsByOrderId(new Integer(orderid).longValue());
	SaleOrderItem item = (SaleOrderItem)list.get(0);
	
	String isflag = ((StorageService)wac.getBean("storageService")).isCompleteProduct(item.getProductName(), item.getProductColor(), item.getSaleOrder().getFlowNo(), meterstring);

	if(isflag.equals("-1")){
		item.setMeterNum(meterstring);
		((SaleOrderItemService)wac.getBean("saleOrderItemService")).updateSaleOrderItem(item);
		isflag = ((SaleOrderItemService)wac.getBean("saleOrderItemService")).isComplete(new Integer(orderid).longValue());
	}else{
		isflag = "-2";
	}
	
 %>
<?xml version="1.0" encoding="GB2312"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card title="订单填充">
	<%
		if(isflag.equals("-1")||isflag.equals("1")){
	 %>
	 <a href="com_detail.jsp?orderid=<%=orderid %>">继续填充该订单</a>
	 <%
	 }
	  %>
	 <%
		if(isflag.equals("-2")){
	 %>
	 <a href="com_detail_com.jsp?orderid=<%=itemid %>">米数错误，返回</a>
	 <%
	 }
	  %> 
	  <%
		if(isflag.equals("2")){
		((SaleOrderService)wac.getBean("saleOrderService")).updateSaleOrderStatus(new Integer(orderid).longValue(),2,"wap");
	 %>
	 <a href="com_list.jsp">该订单填充完毕，继续填充</a>
	 <%
	 }
	  %> 
	</card>
	</wml>
 
